import java.util.Scanner;

/**
 * @author gao
 * @date 2025/10/7 17:56
 */

public class Solution {
    public int numSquares(int n) {
        int[] dp = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            // 最坏情况下，i表示为i个1的
            dp[i] = i;
        }

        for (int i = 1; i <= n; i++) {
            // 尝试所有可能得完全平方数
            for (int j = 1; j * j <= i; j++) {
                dp[i] = Math.min(dp[i], dp[i - j * j] + 1);
            }
        }
        return dp[n];
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int n = in.nextInt();
            Solution solution = new Solution();
            System.out.println(solution.numSquares(n));
        }
    }
}